Skip to content

Answer a limit on a side that is not real with the infinity its direction settles in - #2702

Merged
Rafael-SOWNet merged 2 commits into
masterfrom
fix-2697-directed-infinity-on-a-non-real-side
Dec 4, 2026
Merged

Rafael-SOWNet merged 2 commits into
masterfrom
fix-2697-directed-infinity-on-a-non-real-side

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2697

#2696 left x^(x - 1) at 0 from the left unevaluated, where Gruntz's algorithm had read e^(-i pi) as positive and answered +oo. The principal value there is -1.0E+20 + 3.1i at x = -1e-20 (mpmath): the modulus grows and the argument settles at pi. That is the directed infinity -oo, the same kind of answer ln(x) at 0 from the left already gets.

What changed

  • Gruntz (Gruntz.cs). At the top-level limit, a term c * w^p with p < 0 whose coefficient has no real sign is now read for its direction. Where c tends to a non-zero number, or to an infinity with a direction, on one of the axes, the answer is +oo, -oo, +ooi or -ooi. A direction off the axes declines: x^(x - 1/3) settles at -pi/3, and the library has no node for that direction. A conclusion that a term grows without bound now needs w to be real. Where w is written through an exponent that is not real, its argument can keep turning. x^(1/x) at 0 from the left (phase pi/x) was +oo on master and now declines, and so do six other rows in the sweep below. Two more guards:
    • The gate on analytic functions now looks at their arguments rather than at the whole expression, which lets sin(x)^(x - 2) at 0 from the left be read.
    • A root, or another non-integer constant power, of an argument tending to -oo off the real line now declines, because which side of the cut the argument comes from decides the answer.
  • The descent (Limit.Classes.cs, Transformations.cs). The same cut check is applied to a power's base tending to -oo. sqrt((-x)^(x - 1)) at 0 from the right comes to the cut from below and tends to -ooi, and would otherwise have been +ooi. The logarithm of an infinity in any direction is +oo: ln(sqrt(x) / x) at 0 from the left was ln(-ooi) on master.
  • l'Hôpital's rule (Transformations.cs). The rule is a theorem about real functions. Its proof rests on Cauchy's mean value theorem, which fails for a complex-valued denominator: x / (x + x^2 e^(i/x^2)) at 0 from the right tends to 1 (mpmath gives 1.0 - 7.8E-9i at x = 1e-8), while the quotient of the derivatives tends to 0 (3.9E-9 - 3.1E-9i). The rule now applies only where the denominator's derivative keeps one direction beside the destination: g' = c h' with h' real. That condition is sufficient. The denominator is then g = c h + d, the quotient is the real rule's over h, applied to the numerator's real and imaginary parts separately, and d either vanishes against a growing h or is real where h vanishes.
    • ln(x) at 0 from the left is ln(abs(x)) + i pi, and its derivative 1/x is real, so the rule still applies to it.
    • Where the denominator's derivative turns, the quotient is tried upside down, as 1/g over 1/f. x^pi / log(x, 2) at 0 keeps its 0 that way.
    • "Turns" is a witness: the ratio of the derivative's values at two points beside the destination is not real. The points are 10^-9 and 10^-6 away from a finite destination, or 10^3 and 10^2 out towards an infinity. Other symbols are read as one generic positive number.
    • A power of a negative base to a moving exponent, in either part, also declines the rule. That is for cost, not correctness: its derivatives are the same power again, and the rule kept differentiating them. x^(x - 1) * x at 0 from the left took 5 s to arrive at its 1, and now takes 0.2 s.
  • Two-sided limits (Solvers.Definition.cs). Where both sides agree on an infinity, one side is witnessed not real, and the expression holds a power to a moving exponent that is not real on both sides, the limit stays NaN. This is the convention (-x)^x at 0 already follows. x^(x - 1) / x at 0 is +oo from each side and stays NaN. ln(x) at 0 stays -oo.

Measured on master 82eb869e1 and on this branch.

  • Sweep: 1038 rows. It takes the 432 rows of The limits of x^(x - 1) and (e^x - 1)^(x - 1) at 0- are +oo; the principal value tends to -oo + pi i #2693. It adds f^g with exponents tending to non-integers or not settling, and products with ln, sqrt, x^(±1/2), x^(±1/3), x^(-3/2) and (-x)^a, all at 0 from each side and two-sided. It also has 72 rows at ±oo, and 14 quotients over a complex denominator where l'Hôpital's rule fails: x / (x + x^2 e^(i/x^2)), sin(x) over the same, (1/x) / (1/x + x e^(i/x^2)), x / (x + x^2 e^(i/x)), and two at +oo. Every row is checked against mpmath principal values at ∓1e-10, ∓1e-20 and ∓1e-40, once at those points and once at 1.2345678 times them. The second set is needed because pi/x is a multiple of 2 pi at 1e-10 itself. Each answer is classified by modulus and by arg.
    • master: 651 right, 59 directed-right, 88 NaN with a non-real side, 231 declined, 7 wrong. Two more wrong answers at the infinities were classified "right" because of where the sample points fell: (-x)^x at +oo and x^(-x) at -oo, both +oo, where the phase pi x turns.
    • branch: 670 right, 222 directed-right, 91 NaN with a non-real side, 55 declined, 0 wrong. The complex-denominator rows are declined on both.
    • Changed rows:
      • 163 declined became directed-right.
      • 26 declined became right (mostly 1, and NaN two-sided where the sides differ).
      • 3 declined became NaN with a non-real side.
      • The 9 wrong +oo answers became declined.
      • Seven right answers were lost. They are two-sided NaNs that became declined: x^(1/x) and similar at 0, where the left side no longer answers. The l'Hôpital guard costs no row of the sweep.
      • No row went from right to wrong.
  • Unit tests. C#: 22255 passed, 0 failed, 13 skipped (8 m 57 s). F#: 135 passed. One pinned test changed: AGrownQuotientIsReadWithoutAnotherStepTest.FromTheLeftNothingChanges pinned (sqrt(x) - erf(x)) / x at 0 from the left as unevaluated. Its value is -1.1 - 1.0E+10i at x = -1e-20, so it now expects -ooi, which is what sqrt(x) / x there already is.
  • Tests changed. AnExponentThatOnlyTendsToAWholeNumberIsLeftAloneUnderANegativeBase now expects sin(x)^(x - 2) to be +oo and sin(x)^(x - 1) to be -oo. The limits of x^(x - 1) and (e^x - 1)^(x - 1) at 0- are +oo; the principal value tends to -oo + pi i #2693's IsLeftUnevaluatedFromTheLeft rows now expect their directions. New tests are in ADirectedInfinityOnANonRealSideTest, including two complex-denominator quotients that must not be answered 0.
  • CasBench: 120/121 on both, identical apart from timings.
  • limitcheck: identical reports on master and branch.
  • symlimitcheck: identical reports (190 cases, 731 compared; the 4 wrong and 2 NaN where settled are on master too)

Cost. The sweep took 32 s on the branch against 50 s on master, run back to back. No row is slower than master by more than 1.5x or 1 s, whichever is larger. Only four rows take over 1 s on either side, and all four are complex-denominator rows, declined on both:

row master branch
(1/x) / (1/x + x e^(i/x^2)) at 0 3.9 s 3.8 s
x / (x + x^2 e^(i/x^2)) at 0 1.2 s 1.2 s
sin(x) / (x + x^2 e^(i/x^2)) at 0 1.2 s 1.2 s
(1/x) / (1/x + x e^(i/x^2)) at 0 from the left 1.1 s 1.1 s

The first version of this branch did not have the l'Hôpital guard, and its sweep took 159 s. With directed sub-limits available, nested l'Hôpital steps ran over complex numerators, for example (-x)^(x - 1) * sqrt(x) at 0 from the right went from 0.1 s to 8 s. The guard removes all of that. limitcheck took 28 and 28 s on master against 29 and 28 s on the branch, and symlimitcheck 25 and 25 s on each, run alternately.
BREAKING-CHANGES.md has an entry. A -oo on a side that is not real is a direction, not the real negative infinity, as ln(x) at 0 from the left already is.

🤖 Generated with Claude Code

Rafael-SOWNet and others added 2 commits December 4, 2026 03:31
…tion settles in

x^(x - 1) at 0 from the left, left unevaluated by #2696, is -1.0E+20 + 3.1i at
x = -1e-20 (mpmath): its modulus grows and its argument settles at pi, so it is
-oo, as ln(x) there already is. Gruntz's algorithm now reads the direction of a
leading coefficient that has no real sign, where it settles on an axis: +oo,
-oo, +ooi or -ooi. Off the axes (x^(x - 1/3), at -pi/3) it declines. A term is
read as growing only when w is real: x^(1/x) at 0 from the left, whose phase
pi/x keeps turning, was +oo and now declines, as do six more wrong +oo rows.

A root of an argument tending to -oo off the real line takes its direction from
the side of the cut, and is declined in the algorithm and in the descent:
sqrt((-x)^(x - 1)) at 0 from the right tends to -ooi. The logarithm of an
infinity in any direction is +oo, where ln(sqrt(x) / x) at 0 from the left was
ln(-ooi). Two sides agreeing on an infinity, where one is not real through a
power to a moving exponent, stay NaN, as (-x)^x at 0 is.

AnExponentThatOnlyTendsToAWholeNumberIsLeftAloneUnderANegativeBase pinned
sin(x)^(x - 2) and sin(x)^(x - 1) at 0 from the left as unevaluated; they are
+oo and -oo. FromTheLeftNothingChanges pinned (sqrt(x) - erf(x)) / x there as
unevaluated; it is -ooi, as sqrt(x) / x is. #2693's left-side rows now expect
their directions.

A sweep of 1024 rows (the #2693 432, exponents tending to non-integers or not
settling, products with ln, sqrt and constant powers, and rows at +-oo) against
mpmath at 1e-10, 1e-20 and 1e-40: 7 wrong on master (and two more at the
infinities), 0 here.

Fixes #2697

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tive keeps a direction

The rule is a theorem about real functions; its proof is Cauchy's mean value
theorem, which fails for a complex-valued denominator: x / (x + x^2 e^(i/x^2))
at 0 from the right tends to 1 (1.0 - 7.8E-9i at x = 1e-8, by mpmath), while the
quotient of the derivatives tends to 0. It holds where the denominator's
derivative is c h' with h' real, the quotient then being the real rule's over h,
part by part; ln(x) at 0 from the left, ln(abs(x)) + i pi, qualifies. A
derivative seen to turn beside the destination declines the rule, after the
quotient is tried upside down: x^pi / log(x, 2) at 0 keeps its 0 that way.

A power of a negative base to a moving exponent declines it too, for its cost:
directed sub-limits let the rule differentiate such powers chain after chain,
and x^(x - 1) * x at 0 from the left took 5 s to reach 1, (-x)^(x - 1) sqrt(x)
at 0 from the right 8 s. Both are under 0.3 s now, and the 1038-row sweep runs
in 32 s against master's 50 s with the same answers as before this commit; the
complex-denominator rows are declined, as on master.

Part of #2697

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.11 milestone Dec 4, 2026
@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.31579% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.62%. Comparing base (82eb869) to head (32ea1c3).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...iMath/Functions/Continuous/Limits/Gruntz/Gruntz.cs 84.21% 3 Missing and 3 partials ⚠️
...ns/Continuous/Limits/Solvers/Solvers.Definition.cs 57.14% 1 Missing and 2 partials ⚠️
...nctions/Continuous/Limits/Solvers/Limit.Classes.cs 71.42% 0 Missing and 2 partials ⚠️
...ath/Functions/Continuous/Limits/Transformations.cs 95.34% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #2702    +/-   ##
========================================
  Coverage   86.61%   86.62%            
========================================
  Files         346      346            
  Lines       76754    76864   +110     
  Branches    22554    22604    +50     
========================================
+ Hits        66483    66582    +99     
- Misses       5546     5547     +1     
- Partials     4725     4735    +10     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.11% <86.31%> (+<0.01%) ⬆️
fsharp 32.79% <ø> (ø)
interactive 40.09% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...nctions/Continuous/Limits/Solvers/Limit.Classes.cs 80.47% <71.42%> (+0.59%) ⬆️
...ath/Functions/Continuous/Limits/Transformations.cs 90.11% <95.34%> (+0.21%) ⬆️
...ns/Continuous/Limits/Solvers/Solvers.Definition.cs 88.85% <57.14%> (-1.47%) ⬇️
...iMath/Functions/Continuous/Limits/Gruntz/Gruntz.cs 78.34% <84.21%> (+1.90%) ⬆️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit 6dc3674 into master Dec 4, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Dec 4, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the fix-2697-directed-infinity-on-a-non-real-side branch December 4, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Answer a limit on a side that is not real with its directed infinity where the phase settles

1 participant